//
//  VHBaseViewController.m
//  FruitHelper
//
//  Created by 赵隆杰 on 2021/12/10.
//

#import "VHBaseViewController.h"
#import "VHBaseNavigationController.h"

@interface VHBaseViewController ()

@property (nonatomic, strong) UIView *basic_presentView;
@property (nonatomic, strong) VHBaseViewController *basic_lastVC;

@end

@implementation VHBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = kBgColor;

    self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.tableView.estimatedRowHeight = 0;
    self.tableView.estimatedSectionHeaderHeight = 0;
    self.tableView.estimatedSectionFooterHeight = 0;

    self.tableView.backgroundColor = kViewBgColor;
    self.tableView.scrollsToTop = YES;
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    self.tableView.emptyDataSetSource = self;
    self.tableView.emptyDataSetDelegate = self;
    
    self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SL_WINDOW_WIDTH, CGFLOAT_MIN)];
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SL_WINDOW_WIDTH, CGFLOAT_MIN)];
}

- (void)hdjPresentVC:(VHBaseViewController *)nextVC {
    UIView *backGroundView = [[UIView alloc] initWithFrame:self.view.bounds];
    backGroundView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
    [UIView animateWithDuration:.25 animations:^{
        backGroundView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
    }];
    [self.view addSubview:backGroundView];
    self.basic_presentView = backGroundView;

    nextVC.basic_lastVC = self;

    VHBaseNavigationController *naviVC = [[VHBaseNavigationController alloc] initWithRootViewController:nextVC];
    naviVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    // 是否接管状态栏外观，即重写的 prefersStatusBarHidden 等方法是否会被调用
    naviVC.modalPresentationCapturesStatusBarAppearance = YES;
    [self presentViewController:naviVC animated:YES completion:nil];
}

- (void)hdjDismiss {
    VHBaseViewController *lastVC = self.basic_lastVC;
    if (lastVC.basic_presentView) {
        UIView *tempPresentView = lastVC.basic_presentView;//防止收走后立刻弹起的情况
        [UIView animateWithDuration:.25 animations:^{
            lastVC.basic_presentView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
        } completion:^(BOOL finished) {
            [tempPresentView removeFromSuperview];
        }];
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}


# pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [[UITableViewCell alloc] init];
}

#pragma mark - DZNEmptyDataSetSource
- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
    NSString *title = @"暂无数据";
    NSDictionary *attributes = @{
                                 NSFontAttributeName:[UIFont systemFontOfSize:14],
                                 NSForegroundColorAttributeName:[UIColor colorWithHexString:@"575757"]
                                 };
    return [[NSAttributedString alloc] initWithString:title attributes:attributes];
}
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
    return [UIImage imageNamed:@"nodate"];
}
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
    return YES;
}
- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView{
    return -100;
}
- (void)emptyDataSetWillAppear:(UIScrollView *)scrollView {
    [self.tableView setContentOffset:CGPointMake(0, -self.tableView.contentInset.top)];
}

@end
